package com.linx.park.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.linx.common.idempotent.annotation.RepeatSubmit;
import com.linx.common.log.annotation.Log;
import com.linx.common.web.core.BaseController;
import com.linx.common.mybatis.core.page.PageQuery;
import com.linx.common.core.domain.R;
import com.linx.common.core.validate.AddGroup;
import com.linx.common.core.validate.EditGroup;
import com.linx.common.log.enums.BusinessType;
import com.linx.common.excel.utils.ExcelUtil;
import com.linx.park.domain.vo.ParkInfoVo;
import com.linx.park.domain.bo.ParkInfoBo;
import com.linx.park.service.IParkInfoService;
import com.linx.common.mybatis.core.page.TableDataInfo;

/**
 * 园区信息
 *
 * @author 泽智科技
 * @date 2024-10-04
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/park/park-info")
public class ParkInfoController extends BaseController {

    private final IParkInfoService parkInfoService;

    /**
     * 查询园区信息列表
     */
    @SaCheckPermission("park:park-info:list")
    @GetMapping("/list")
    public TableDataInfo<ParkInfoVo> list(ParkInfoBo bo, PageQuery pageQuery) {
        return parkInfoService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出园区信息列表
     */
    @SaCheckPermission("park:park-info:export")
    @Log(title = "园区信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ParkInfoBo bo, HttpServletResponse response) {
        List<ParkInfoVo> list = parkInfoService.queryList(bo);
        ExcelUtil.exportExcel(list, "园区信息", ParkInfoVo.class, response);
    }

    /**
     * 获取园区信息详细信息
     *
     * @param parkInfoId 主键
     */
    @SaCheckPermission("park:park-info:query")
    @GetMapping("/{parkInfoId}")
    public R<ParkInfoVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long parkInfoId) {
        return R.ok(parkInfoService.queryById(parkInfoId));
    }

    /**
     * 新增园区信息
     */
    @SaCheckPermission("park:park-info:add")
    @Log(title = "园区信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ParkInfoBo bo) {
        return toAjax(parkInfoService.insertByBo(bo));
    }

    /**
     * 修改园区信息
     */
    @SaCheckPermission("park:park-info:edit")
    @Log(title = "园区信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ParkInfoBo bo) {
        return toAjax(parkInfoService.updateByBo(bo));
    }

    /**
     * 删除园区信息
     *
     * @param parkInfoIds 主键串
     */
    @SaCheckPermission("park:park-info:remove")
    @Log(title = "园区信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{parkInfoIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] parkInfoIds) {
        return toAjax(parkInfoService.deleteWithValidByIds(List.of(parkInfoIds), true));
    }
}
